from flaskapp.exts import db


class Consultation(db.Model):
    __tablename__ = 'consultations'

    consultation_id = db.Column(db.Integer, primary_key=True)
    from_whom = db.Column(db.Integer, nullable=False)
    content = db.Column(db.Text)
    date = db.Column(db.Date, nullable=False)
    is_processed = db.Column(db.Boolean, nullable=False, default=False)

    def __init__(self, from_whom, content, date):
        self.from_whom = from_whom
        self.content = content
        self.date = date
        self.is_processed = False
        db.session.add(self)
        db.session.commit()

    def to_dict(self):
        return {
            'consultation_id': self.consultation_id,
            'from_whom': self.from_whom,
            'content': self.content,
            'date': self.date,
            'is_processed': self.is_processed
        }

    def beProcessed(self):
        self.is_processed = True
        db.session.commit()

